<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 * $Log$
 *
 */
set_time_limit(0);
include("../config.inc.php");
include(__Common_Path."/AllWeb.inc.php");

$strTmp1 = "<tr>
	<td class='web-name'>{No}</td>
	<td class='web-name'>{Web}</td>
	<td class='web-td' id='GetTime{No}'>{GetTime}</td>
</tr>";

$intNo = 0;
$arrWeb = array();
$arrWebCon = array();
foreach($_arrWeb as $key => $arrV){
	$strTmp = $strTmp1;
	$intNo++;	

	$strTmp = str_replace("{Web}", $arrV[1]." (".$arrV[0].")", $strTmp);
	$strTmp = str_replace("{No}", $intNo, $strTmp);
	$strTmp = str_replace("{GetTime}", $strCon, $strTmp);
	$arrWeb[] = "'".$arrV[0]."'";
	$arrWebCon[] = $strTmp;
}

?>
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> Get Web Time </title>
<style>
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-size: 12px
	font-family: Arial, Helvetica, Verdana, Geneva,  sans-serif;
	background-color: #EFFFDF;
}
td {
	font-size: 12px
	font-family: Arial, Helvetica, Verdana, Geneva,  sans-serif;
	background-color: #FFFFFF;
	text-align: center;
}
.showTable {
	background-color: #9DBAD8;
	border: 1px solid #056FD8;
}
.web-td {
	text-align: right;
	padding-right: 2px;
}
.web-name {
	text-align: left;
	padding-left: 2px;
}
//-->
</style>
<script type="text/javascript" language="javascript">
<!--
var arrURL = [<?php print implode(", ", $arrWeb);?>];

var arrTime = new Array();
var objTTT = new Date();
var intResponeNo = 0;

function callServer(i) {
	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	// 定義事件處理函數為 alterContents()
	http_request.onreadystatechange = function() { 
                                      alertContents(http_request, i); };
	objTTT = new Date();
	arrTime[i] = objTTT.getTime();
	var url = "http://admin." + arrURL[i] + "/index.php?t="+arrTime[i];
	document.getElementById("GetTime"+(i+1)).innerHTML = "<b style='color: #0000FF'>wait....("+Math.floor(arrTime[i] / 1000)+")</b>";

	http_request.open('GET', url, true);
	http_request.send(null);
}

function alertContents(http_request, i) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var restext = http_request.responseText;
			var strURL = arrURL[i].replace('admin.', '');
			objTTT = new Date();
			var intGapTime = (objTTT.getTime() - arrTime[i]) / 1000;

			if(restext.indexOf(strURL) >= 0){
				if(intGapTime > 10){
					document.getElementById("GetTime"+(i+1)).innerHTML = "<b style='color: #FF0000'>"+intGapTime+"</b>";
				}else{
					document.getElementById("GetTime"+(i+1)).innerHTML = intGapTime;
				}
			}else{
				document.getElementById("GetTime"+(i+1)).innerHTML = "<b> Not Get </b>";
			}
		} else {
			document.getElementById("GetTime"+(i+1)).innerHTML = "<b> Not Get </b>";
		}
	}
	intResponeNo++;
	if(intResponeNo >= arrURL.length){
		setTimeout("showTime()", 5000);
	}
}

function ccc(){
	intResponeNo = 0;
	for(var i = 0; i < arrURL.length; i++){
		callServer(i);
	}
}
//-->
</script>
</head>

<body onload="ccc()">
<table  border="0" cellspacing="1" cellpadding="0" class="showTable">
<tr>
	<td width="50">序號</td>
	<td width="250">網站</td>
	<td width="100">秒數</td>
</tr>
<?php print implode("", $arrWebCon);?>
</table>
現在時間：<?php print date("Y-m-d H:i:s");?><br /><br />
</body>
</html>